﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DoAn.DTO;
using DoAn.BUS;
using System.Windows.Forms;

namespace DoAn
{
    public partial class MasterPageNguoiDung : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DisplayLoginInfo();
        }
        private void DisplayLoginInfo()
        {
            
            if (TaiKhoanBUS.isLogged())
            {                           
                if (TaiKhoanBUS.loaiTaiKhoan() == "True")
                {
                    hplTenTaiKhoan.Text = "Xin Chào: " + TaiKhoanBUS.tenTaiKhoan();
                    hplTenTaiKhoan.NavigateUrl = "TaiKhoanCuaToi.aspx?tentk=" + TaiKhoanBUS.tenTaiKhoan();
                    hplDangKi.Visible = false;
                    hplMua.Visible = false;
                    hplBan.Visible = false;
                    bntThoat.Visible = true;
                    hplDangNhap.Visible = false;
                    hplQuanLi.Visible = true;
                }
                else
                {
                    hplTenTaiKhoan.Text = "Xin Chào: " + TaiKhoanBUS.tenTaiKhoan();
                    hplTenTaiKhoan.NavigateUrl = "TaiKhoanCuaToi.aspx?tentk=" + TaiKhoanBUS.tenTaiKhoan();
                    hplDangKi.Visible = false;
                    hplMua.Visible = true;
                    hplBan.Visible = true;
                    bntThoat.Visible = true;
                    hplDangNhap.Visible = false;
                    hplQuanLi.Visible = false;
                }
            }
            else
            {
                hplMua.Visible = false;
                hplDangKi.Visible = true;
                bntThoat.Visible = false;
                hplBan.Visible = false;
                hplTenTaiKhoan.Visible = false;
                hplQuanLi.Visible = false;
            }
        }

        protected void bntThoat_Click(object sender, EventArgs e)
        {
            Response.Cookies["TenTaiKhoan"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["LoaiTaiKhoan"].Expires = DateTime.Now.AddDays(-1);
            Response.Redirect(Request.Url.ToString());
        }

    }
}